﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NUS.ISS.ARS.Web.PageController;

namespace NUS.ISS.ARS.Web.Booking
{
    public partial class SearchBookings : BookingBaseController
    {
        bool _isValid;

        protected void Page_Load(object sender, EventArgs e)
        {
            CurrentPage = "SearchBookings.aspx";
            base.Page_Load(sender, e);
            lblMsg.Text = "";

            if (!Page.IsPostBack)
            {
                ClearSessions();
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string bookingRef = txtBookingRef.Text.Trim();
            string firstName = txtFirstName.Text.Trim();
            string lastName = txtLastName.Text.Trim();

            //Validate(bookingRef, firstName, lastName);

            //if (_isValid)
            //{
                SearchBookings(bookingRef, firstName, lastName);
                MoveToNextPage();
            //}
        }

        private void Validate(string bookingRef, string firstName, string lastName)
        {
            _isValid = true;

            if (String.IsNullOrEmpty(bookingRef))
            {
                ShowErrorMessage("Please enter the booking reference. <br />");
            }

            if (String.IsNullOrEmpty(firstName))
            {
                ShowErrorMessage("Please enter the first name. <br />");
            }

            if (String.IsNullOrEmpty(lastName))
            {
                ShowErrorMessage("Please enter the last name. <br />");
            }
        }

        private void ShowErrorMessage(string msg) 
        {
            lblMsg.Text += msg;
            _isValid = false;
        }
    }
}